package com.timmy.test1.view;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PixelFormat;
import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.View;

import com.timmy.test1.R;

/**
 * Created by timmy on 2020/5/7.
 */

public class CustomRockerView extends CustomKeyView {
    private static final int AREA_BACKGROUND_MODE_COLOR = 1;

    private static final int AREA_BACKGROUND_MODE_DEFAULT = 3;

    private static final int AREA_BACKGROUND_MODE_PIC = 0;

    private static final int AREA_BACKGROUND_MODE_XML = 2;

    private static final int DEFAULT_ROCKER_RADIUS = 50;

    private static final int DEFAULT_SIZE = 400;

    private static final int ROCKER_BACKGROUND_MODE_COLOR = 5;

    private static final int ROCKER_BACKGROUND_MODE_DEFAULT = 7;

    private static final int ROCKER_BACKGROUND_MODE_PIC = 4;

    private static final int ROCKER_BACKGROUND_MODE_XML = 6;

    private static final String TAG = "RockerView";

    private int mAreaBackgroundMode = 3;

    private Paint mAreaBackgroundPaint;

    private Bitmap mAreaBitmap;

    private int mAreaColor;

    private int mAreaRadius;

    private Point mCenterPoint;

    private int mRockerBackgroundMode = 7;

    private Bitmap mRockerBitmap;

    private int mRockerColor;

    private Paint mRockerPaint;

    private Point mRockerPosition;

    private int mRockerRadius;

    private int mRockerType = 0;

    public CustomRockerView(Context paramContext) {
        this(paramContext, (AttributeSet) null);
    }

    public CustomRockerView(Context paramContext, AttributeSet paramAttributeSet) {
        super(paramContext, paramAttributeSet);
        initAttribute(paramContext, paramAttributeSet);
        isInEditMode();
        Paint paint = new Paint();
        this.mAreaBackgroundPaint = paint;
        paint.setAntiAlias(true);
        paint = new Paint();
        this.mRockerPaint = paint;
        paint.setAntiAlias(true);
        this.mCenterPoint = new Point();
        this.mRockerPosition = new Point();
    }

    private Bitmap drawable2Bitmap(Drawable paramDrawable) {
        Bitmap.Config config;
        int i = paramDrawable.getIntrinsicWidth();
        int j = paramDrawable.getIntrinsicHeight();
        if (paramDrawable.getOpacity() != PixelFormat.OPAQUE) {
            config = Bitmap.Config.ARGB_8888;
        } else {
            config = Bitmap.Config.RGB_565;
        }
        Bitmap bitmap = Bitmap.createBitmap(i, j, config);
        Canvas canvas = new Canvas(bitmap);
        paramDrawable.setBounds(0, 0, i, j);
        paramDrawable.draw(canvas);
        return bitmap;
    }

    private void initAttribute(Context paramContext, AttributeSet paramAttributeSet) {
        TypedArray typedArray = paramContext.obtainStyledAttributes(paramAttributeSet, R.styleable.RockerView);
        Drawable drawable = typedArray.getDrawable(0);
        if (drawable != null) {
            if (drawable instanceof BitmapDrawable) {
                this.mAreaBitmap = ((BitmapDrawable) drawable).getBitmap();
                this.mAreaBackgroundMode = 0;
            } else if (drawable instanceof android.graphics.drawable.GradientDrawable) {
                this.mAreaBitmap = drawable2Bitmap(drawable);
                this.mAreaBackgroundMode = 2;
            } else if (drawable instanceof ColorDrawable) {
                this.mAreaColor = ((ColorDrawable) drawable).getColor();
                this.mAreaBackgroundMode = 1;
            } else {
                this.mAreaBackgroundMode = 3;
            }
        } else {
            this.mAreaBackgroundMode = 3;
        }
        drawable = typedArray.getDrawable(R.styleable.RockerView_areaBackground);
        if (drawable != null) {
            if (drawable instanceof BitmapDrawable) {
                this.mRockerBitmap = ((BitmapDrawable) drawable).getBitmap();
                this.mRockerBackgroundMode = 4;
            } else if (drawable instanceof android.graphics.drawable.GradientDrawable) {
                this.mRockerBitmap = drawable2Bitmap(drawable);
                this.mRockerBackgroundMode = 6;
            } else if (drawable instanceof ColorDrawable) {
                this.mRockerColor = ((ColorDrawable) drawable).getColor();
                this.mRockerBackgroundMode = 5;
            } else {
                this.mRockerBackgroundMode = 7;
            }
        } else {
            this.mRockerBackgroundMode = 7;
        }
        this.mRockerType = typedArray.getInteger(R.styleable.RockerView_rockerType, 0);
        this.mRockerRadius = typedArray.getDimensionPixelOffset(R.styleable.RockerView_rockerRadius, 50);
        typedArray.recycle();
    }

    public int getRockerType() {
        return this.mRockerType;
    }

    @Override
    protected void onDraw(Canvas paramCanvas) {
        super.onDraw(paramCanvas);
        int k = getMeasuredWidth();
        int m = getMeasuredHeight();
        int i = k / 2;
        int j = m / 2;
        this.mCenterPoint.set(i, j);
        if (k > m) {
            i = j;
        }
        this.mAreaRadius = i;
        this.mRockerPosition.set(this.mCenterPoint.x, this.mCenterPoint.y);
        i = this.mAreaBackgroundMode;
        if (i == 0 || 2 == i) {
            Rect rect1 = new Rect(0, 0, this.mAreaBitmap.getWidth(), this.mAreaBitmap.getHeight());
            Rect rect2 = new Rect(this.mCenterPoint.x - this.mAreaRadius, this.mCenterPoint.y - this.mAreaRadius, this.mCenterPoint.x + this.mAreaRadius, this.mCenterPoint.y + this.mAreaRadius);
            paramCanvas.drawBitmap(this.mAreaBitmap, rect1, rect2, this.mAreaBackgroundPaint);
        } else if (1 == i) {
            this.mAreaBackgroundPaint.setColor(this.mAreaColor);
            paramCanvas.drawCircle(this.mCenterPoint.x, this.mCenterPoint.y, this.mAreaRadius, this.mAreaBackgroundPaint);
        } else {
            this.mAreaBackgroundPaint.setColor(-7829368);
            paramCanvas.drawCircle(this.mCenterPoint.x, this.mCenterPoint.y, this.mAreaRadius, this.mAreaBackgroundPaint);
        }
        i = this.mRockerBackgroundMode;
        if (4 == i || 6 == i) {
            Rect rect1 = new Rect(0, 0, this.mRockerBitmap.getWidth(), this.mRockerBitmap.getHeight());
            Rect rect2 = new Rect(this.mRockerPosition.x - this.mRockerRadius, this.mRockerPosition.y - this.mRockerRadius, this.mRockerPosition.x + this.mRockerRadius, this.mRockerPosition.y + this.mRockerRadius);
            paramCanvas.drawBitmap(this.mRockerBitmap, rect1, rect2, this.mRockerPaint);
            return;
        }
        if (5 == i) {
            this.mRockerPaint.setColor(this.mRockerColor);
            paramCanvas.drawCircle(this.mRockerPosition.x, this.mRockerPosition.y, this.mRockerRadius, this.mRockerPaint);
            return;
        }
        this.mRockerPaint.setColor(-65536);
        paramCanvas.drawCircle(this.mRockerPosition.x, this.mRockerPosition.y, this.mRockerRadius, this.mRockerPaint);
    }

    @Override
    protected void onMeasure(int paramInt1, int paramInt2) {
        int j = View.MeasureSpec.getMode(paramInt1);
        int i = View.MeasureSpec.getMode(paramInt2);
        paramInt1 = View.MeasureSpec.getSize(paramInt1);
        paramInt2 = View.MeasureSpec.getSize(paramInt2);
        if (j != MeasureSpec.EXACTLY) {
            paramInt1 = 400;
        }
        if (i != MeasureSpec.EXACTLY) {
            paramInt2 = 400;
        }
        setMeasuredDimension(paramInt1, paramInt2);
    }

    public void setRockBackIn(Bitmap paramBitmap) {
        this.mRockerBackgroundMode = 4;
        this.mRockerBitmap = paramBitmap;
        invalidate();
    }

    public void setRockBackOut(Bitmap paramBitmap) {
        this.mAreaBitmap = paramBitmap;
        invalidate();
    }

    public void setRockerRadiusBySize(int paramInt) {
        this.mRockerRadius = (int) ((paramInt - 5) * 0.1D * 50.0D + 50.0D);
        requestLayout();
        invalidate();
    }
}


/* Location:              C:\Users\timmy\Documents\Tencent Files\825125501\FileRecv\0xcfd85000-dex2jar.jar!\cn\ji_cloud\android\views\CustomRockerView.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       1.1.3
 */